//
//  twodimensionVC.m
//  SeaChat
//
//  Created by dllo on 16/6/16.
//  Copyright © 2016年 潘强. All rights reserved.
//

#import "twodimensionVC.h"
#import "UIImage+PQTwodimension.h"
#define Width self.view.frame.size.width
#define Height self.view.frame.size.height

@interface twodimensionVC ()




@end

@implementation twodimensionVC

-(void)dealloc{
    [_TwoImageview release];
    [_titleLabel release];
    [_UserImageView release];
    [_UserName release];
    [_UserNumber release];
    [_WordLabel release];
    [_smallView release];
    [super dealloc];
}

#pragma mark 在此实现方法

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self two];
    
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
//    [self two];
    
    self.TwoImageview = [UIImageView new];
    self.TwoImageview.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:self.TwoImageview];
//    self.TwoImageview.frame = CGRectMake(100, 100, 300, 300);
    [self.TwoImageview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(self.view);
        make.left.mas_equalTo(Width * 0.15);
        make.right.mas_equalTo(-Width *0.15);
        make.top.mas_equalTo(Height * 0.3);
        make.bottom.mas_equalTo(-Height * 0.3);
    }];
    
    
    self.titleLabel = [UILabel new];
    self.titleLabel.text = @"扫描二维码图案,加我为好友";
    self.titleLabel.backgroundColor = [UIColor whiteColor];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_TwoImageview);
        make.right.mas_equalTo(_TwoImageview);
        make.top.mas_equalTo(_TwoImageview.mas_bottom);
        make.height.mas_equalTo(25);
        
    }];
 //头像图片
    self.UserImageView = [UIImageView new];
    self.UserImageView.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.UserImageView];
    
    [self.UserImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.size.mas_equalTo(CGSizeMake(80, 80));
        make.top.mas_equalTo(84);
    }];
  //昵称
    self.UserName = [UILabel new];
    self.UserName.backgroundColor = [UIColor greenColor];
    self.UserName.text = @"昵称";
    [self.view addSubview:self.UserName];
    [self.UserName mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(_UserImageView.mas_right).offset(10);
        make.size.mas_equalTo(CGSizeMake(200, 30));
        make.top.mas_equalTo(94);

    }];

    //账户
    self.WordLabel = [UILabel new];
    self.WordLabel.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:self.WordLabel];
    self.WordLabel.text = @"账号:";
    [self.WordLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(_UserImageView.mas_right).offset(10);
        make.size.mas_equalTo(CGSizeMake(40, 30));
        make.top.mas_equalTo(130);
        
    }];
 //账户号
    self.UserNumber = [UILabel new];
    self.UserNumber.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:self.UserNumber];
    [self.UserNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(_WordLabel.mas_right);
        make.size.mas_equalTo(CGSizeMake(160, 30));
        make.top.mas_equalTo(130);
        
    }];

    
    
  
    //头像图片
    self.smallView = [UIImageView new];
    self.smallView.backgroundColor = [UIColor redColor];
    [self.TwoImageview addSubview:self.smallView];
    [self.smallView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(_TwoImageview);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    
    
    
}




-(void)two{
    
    
    
    // 1. 创建一个二维码滤镜实例(CIFilter)
    CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
    // 滤镜恢复默认设置
    [filter setDefaults];
    
    // 2. 给滤镜添加数据
    NSString *string = @"http://www.jianshu.com/users/db6844a150fb/latest_articles";
    NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
    
    [filter setValue:data forKeyPath:@"inputMessage"];
    
    // 3. 生成二维码
    CIImage *image = [filter outputImage];
    // 4. 显示二维码
    //    twoVC.TwoImageview.image = [UIImage imageWithCIImage:image];
    NSLog(@"%@....",[UIImage imageWithCIImage:image]);
   self.TwoImageview.image = [UIImage createNonInterpolatedUIImageFormCIImage:image withSize:500];
    
}







@end
